//
//  AppDelegate.m
//  UniverseProject
//
//  Created by ETOP on 2018/2/25.
//  Copyright © 2018年 Cloud2209. All rights reserved.
//

#import <IQKeyboardManager.h>
#import "HomePageC.h"
#import "BONaviViewController.h"
#import "ZBTabbarViewController.h"
#import "LGBaseViewController.h"
#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //初始化项目
    [self initAppEntrancy];

    //定时器处理
    [self timerHandle];
    
    //键盘控制
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    
    //app支持摇动调试
    [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];
    
    return YES;
}


#pragma mark - 初始化界面
- (void)initAppEntrancy{
    BONaviViewController *navC = [[BONaviViewController alloc] initWithRootViewController:[HomePageC new]];
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = navC;
    [self.window makeKeyAndVisible];
}


#pragma mark - 初始化界面
//- (void)initAppEntrancyWithTabbar{
//    ZBTabbarViewController *navC = [[ZBTabbarViewController alloc] init];
//    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
//    self.window.backgroundColor = [UIColor whiteColor];
//    self.window.rootViewController = navC;
//    [self.window makeKeyAndVisible];
//}

#pragma mark - 初始化资源



#pragma mark - 定时器处理
- (void)timerHandle{
    //定时器后台执行
    // Override point for customization after application launch.
    NSError *setCategoryErr = nil;
    NSError *activationErr  = nil;
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryErr];
    [[AVAudioSession sharedInstance] setActive: YES error: &activationErr];
}

- (void)applicationDidEnterBackground:(UIApplication *)application{

    //定时器处理
    UIApplication*   app = [UIApplication sharedApplication];
    __block    UIBackgroundTaskIdentifier bgTask;
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            if (bgTask != UIBackgroundTaskInvalid)
            {
                bgTask = UIBackgroundTaskInvalid;
            }
        });
    }];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            if (bgTask != UIBackgroundTaskInvalid)
            {
                bgTask = UIBackgroundTaskInvalid;
            }
        });
    });
}



@end
